import React from "react";
import BaseStore from "@/base/BaseStore";
import {Message} from "@biz/Components";

export default class Store extends BaseStore{
    constructor(props,config, action) {
        super(props, config, action)
        this.state = this.getInitialState()
    }

    getInitialSo() {
        return {
        }
    }

    // 店铺经纬度
    onInitShopGeo(){
        this.setState({geoLoading:true})
    }
    onInitShopGeoCompleted(res){
        this.setState({geoLoading:false})
        super.dealResponse(res,()=>{
            let count = res.vo;
            Message.success("处理店铺个数："+count);
        });
    }

    // 充值订单支付状态
    onQueryWxPayInfo(){
        this.setState({payQueryLoading:true})
    }
    onQueryWxPayInfoCompleted(res){
        this.setState({payQueryLoading:false})
        super.dealResponse(res,()=>{
            let transaction = res.vo;
            let {tradeStateDesc, outTradeNo,transactionId} = transaction
            Message.success(<div className="w-300 text-left">
                <div>内部单号：{outTradeNo}</div>
                <div>微信单号：{transactionId}</div>
                <div>支付状态：{tradeStateDesc}</div>
            </div>);
        });
    }

    // 充值订单支付状态
    onQueryWxRefundInfo(){
        this.setState({refundQueryLoading:true})
    }
    onQueryWxRefundInfoCompleted(res){
        this.setState({refundQueryLoading:false})
        super.dealResponse(res,()=>{
            let refund = res.vo;
            let {refundStatus, outTradeNo,transactionId, refundId} = refund
            Message.success(<div className="w-300 text-left">
                <div>内部单号：{outTradeNo}</div>
                <div>微信单号：{transactionId}</div>
                <div>退款单号：{refundId}</div>
                <div>支付状态：{refundStatus}</div>
            </div>);
        });
    }


    // 设备测试
    onTestDevice(subAddress, pubAddress){
        this.setState({testDeviceLoading:true,subAddress, pubAddress,deviceList:[]})
    }
    onTestDeviceCompleted(res){
        this.setState({testDeviceLoading:false})
        super.dealResponse(res,()=>{
            let {subAddress, pubAddress} = this.state;
            let {msg, deviceList=[]} = res.vo;
            let len = deviceList.length;
            deviceList.forEach(o=>{
                o.label = `${o.id} - ${o.name} (${o.shopName})`;
            })
            let newState = {deviceList};
            if(len>0){
                let id = deviceList[0].id;
                newState.deviceIdSelectValue= id;
                newState.deviceId = id;
            }
            this.setState(newState);
            Message.success(<div className="w-300 text-left">
                <div>订阅地址：{subAddress}</div>
                <div>发布地址：{pubAddress}</div>
                <div>返回信息：{msg}</div>
                <div>设备：{len==0 ? "未找到关联的内部设备" : `找到${len}条内部设备记录`}</div>
            </div>);
        });
    }
    // 设备测试
    onBindDevice(subAddress, pubAddress){
        this.setState({bindDeviceLoading:true,subAddress, pubAddress})
    }
    onBindDeviceCompleted(res){
        this.setState({bindDeviceLoading:false})
        super.dealResponse(res,()=>{
            let {subAddress, pubAddress} = this.state;
            let msg = res.vo;
            Message.success(<div className="w-300 text-left">
                <div>订阅地址：{subAddress}</div>
                <div>发布地址：{pubAddress}</div>
                <div>返回信息：{msg}</div>
            </div>);
        });
    }

    onJparkingDiscount(){
        this.setState({jparkingDiscountLoading:true})
    }
    onJparkingDiscountCompleted(res){
        this.setState({jparkingDiscountLoading:false})
        super.dealResponse(res,()=>{

            let msg = JSON.stringify(res.vo);
            Message.success(<div className="w-300 text-left">
                <div>返回信息：{msg}</div>
            </div>);
        });
    }
    onJparkingSearch(){
        this.setState({jparkingSearchLoading:true})
    }
    onJparkingSearchCompleted(res){
        this.setState({jparkingSearchLoading:false})
        super.dealResponse(res,()=>{
            let {data=[]} = res.vo;
            this.setState({jparkingVoList:data})
        });
    }
    onJparkingAccountListCompleted(res){
        super.dealResponse(res,()=>{
            let {voList=[]} = res;
            let  jparkingAccountId = null;
            if(voList && voList.length>0){
                jparkingAccountId = voList[0].id;
            }
            this.setState({jparkingAccountList:voList, jparkingAccountId})
        });
    }
}